package com.example.controller;

import com.example.pojo.*;
import com.example.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * StudentController 类的描述信息
 *
 * @author 12427
 * @since 2025/6/7 13:10
 */
@Slf4j
@RestController
@RequestMapping("/students")
public class StudentController {
    @Autowired
    private StudentService studentService;

//        获取所有学生 分页
    @GetMapping
    public Result page(StudentQueryParam studentQueryParam) {
        log.info("分页查询");
        PageResult<Student> pageResult=studentService.page(studentQueryParam);
        return Result.success(pageResult);
    }
    /**
     * 删除学员
     */
    @DeleteMapping("/{ids}")//是路径参数  PathVariable指定路径
    public Result delete(@PathVariable List<Integer> ids) {
        log.info("删除学员");
        studentService.deletrById(ids);
        return Result.success();
    }
    /**
     *      添加学员
     **/
    @PostMapping//@RequestBody
    public Result input(@RequestBody Student student){
        studentService.input( student);
        return Result.success();
    }
    /**
     *  根据ID查询学生
     */
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id) {
        log.info("查询学生");
        Student student = studentService.getInfo(id);
        return Result.success(student);
    }
    /**
     *  修改学员
     */
    @PutMapping//RequestBody
    public Result update(@RequestBody Student student) {
        log.info("修改学员");
        studentService.update(student);
        return Result.success();
    }
    /**
     *  学员违纪扣分
     */
    @PutMapping("/violation/{id}/{score}")
    public Result deduct(@PathVariable Integer id, @PathVariable Integer score) {
        log.info("学员违纪扣分");
        studentService.updatesore(id,score);
        return Result.success();
    }
}
